/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.actions.classGroupManagement;

import cassys.actions.core.BaseAction;
import cassys.domain.classManagement.ClassGroup;
import cassys.domain.classManagement.Module;
import cassys.domain.classManagement.Student;
import cassys.ejb.clients.ClassGroupManagementDelegate;
import cassys.ejb.clients.ModuleManagementDelegate;
import cassys.ejb.clients.StudentManagementDelegate;
import java.util.List;

/**
 *
 * @author User
 */
public class CreateClassGroup extends BaseAction {

    private String title;
    private Module module;
    //private List<Student> clasMembers;
    private List<Module> modules;
    private List<Student> students;
    private ClassGroupManagementDelegate classGroupDelegate;
    private StudentManagementDelegate studentDelegate;
    private ModuleManagementDelegate moduleDelegate;

    public CreateClassGroup() {
        classGroupDelegate = new ClassGroupManagementDelegate();
        studentDelegate = new StudentManagementDelegate();
        moduleDelegate = new ModuleManagementDelegate();
    }

    @Override
    public String execute() throws Exception {
        setModules(moduleDelegate.getAllModules());
        System.out.println("got modules");
        setStudents(studentDelegate.getAllStudents());
        System.out.println("classGroup management action started");
        return SUCCESS;
    }

    public String createNewClassGroup() throws Exception {
        System.out.println("invoke create classGroup action");
        System.out.println(this.students.size());
       classGroupDelegate.createClassGroup(getNewClassGroup());

        // classGroupDelegate.createClassGroup(classGroupDTO);
        return SUCCESS;
    }

    private ClassGroup getNewClassGroup() {

        ClassGroup newClassGroup = new ClassGroup(this.module, this.title);
        for (Student student : students) {
            newClassGroup.addStudent(student);
        }
        return newClassGroup;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the module
     */
    public Module getModule() {
        return module;
    }

    /**
     * @param module the module to set
     */
    public void setModule(Module module) {
        this.module = module;
    }

    /**
     * @return the modules
     */
    public List<Module> getModules() {
        return modules;
    }

    /**
     * @param modules the modules to set
     */
    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    /**
     * @return the students
     */
    public List<Student> getStudents() {
        return students;
    }

    /**
     * @param students the students to set
     */
    public void setStudents(List<Student> students) {
        this.students = students;
    }
}
